package com.chinasoft.ecommerceconsumptionanalysissystem.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Mapper
public interface ElectronicsSaleMapper {
    Map<String, Object> getKPI(@Param("startDate") Date startDate
            , @Param("endDate") Date endDate);

    List<Map<String, Object>> getCTByDay(@Param("startDate") Date startDate
            , @Param("endDate") Date endDate);

    List<Map<String, Object>> getCTByWeek(@Param("sortType") String sortType
            , @Param("targetDate") Date targetDate);

    List<Map<String, Object>> getCTByMonth(@Param("year") Date year);

    List<Map<String, Object>> getCTByLocalAndTime(@Param("startDate") Date startDate, @Param("endDate") Date endDate);

    List<Map<String, Object>> getCTByLocal();

    List<Map<String, Object>> getProductCombination(@Param("number") int number);

    Map<String, Object> getProductRepurchaseRate(@Param("productId") Long productId
            , @Param("startDate") Date startDate, @Param("endDate") Date endDate);

    List<Map<String, Object>> getHighRepurchaseBrand(@Param("number") int number
            , @Param("startDate") Date startDate, @Param("endDate") Date endDate);

    List<Map<String, Object>> getHighRepurchaseCategory(@Param("number") int number
            , @Param("startDate") Date startDate, @Param("endDate") Date endDate);

    List<Map<String, Object>> detectRepeatOrderByUser(@Param("timeWindow") int timeWindow
            , @Param("startDate") Date startDate, @Param("endDate") Date endDate);

    List<Map<String, Object>> detectAbnormalHighPriceOrder(@Param("startDate") Date startDate
            , @Param("endDate") Date endDate);

    List<Map<String, Object>> detectAbnormalConsumeUser(@Param("orderCountThreshold") int orderCountThreshold
            , @Param("amountThreshold") Double amountThreshold, @Param("startDate") Date startDate
            , @Param("endDate") Date endDate);

    /**
     * 品类维度：销量/销售额占比，按销量降序
     */
    List<Map<String, Object>> getCategoryRatio();

    /**
     * 指定品类下头部品牌市场份额（销量/销售额占比）
     *
     * @param categoryCode 品类编码，如 electronics.smartphone
     * @param topN         取前 N 个品牌
     */
    List<Map<String, Object>> getBrandShareInCategory(@Param("categoryCode") String categoryCode,
                                                      @Param("topN") int topN);

    /**
     * 每个年龄段、每个品类的销量
     * 结果按年龄段内销量倒序
     */
    List<Map<String, Object>> getCategoryByAgeLayer(@Param("ageLayer") String ageLayer);

    /**
     * 每个年龄段、每个用户的“消费能力”
     * 消费能力 = 该用户在该年龄段买过最贵的 1 件商品的价格
     */
    List<Map<String, Object>> getUserPowerByAgeLayer(@Param("ageLayer") String ageLayer);

    /* ===== 性别维度：品类销量 & 用户消费能力 ===== */
    List<Map<String,Object>> getCategoryBySex(@Param("sex") String sex);
    List<Map<String,Object>> getUserPowerBySex(@Param("sex") String sex);

    /* ===== 地区维度：品类销量 & 用户消费能力 ===== */
    List<Map<String,Object>> getCategoryByProvince(@Param("province") String province);
    List<Map<String,Object>> getUserPowerByProvince(@Param("province") String province);

    int getCount();
}
